﻿singleApp.controller('member_editCtrl', ['$http', '$scope', function ($http, $scope) {
    $scope.model = {
        id: window.singleConfig.id,
        user_name: window.singleConfig.user_name,
        phone: window.singleConfig.phone,
        child_count: window.singleConfig.child_count,
        total_child_count: window.singleConfig.total_child_count
    };

    $scope.confirm = function () {
        if ($scope.model.user_name == "") {
            layer.msg("用户名不能为空！");
            return;
        }

        if ($scope.model.phone == "") {
            layer.msg("手机号不能为空！");
            return;
        }

        if (Math.floor($scope.model.child_count) === parseInt($scope.model.child_count)
            && Math.floor($scope.model.total_child_count) === parseInt($scope.model.total_child_count)) {
            var api_url = window.singleConfig.rootUrl + 'api/admin/UsersService/memberEdit';
            layer.load(2);
            $http({
                method: 'POST',
                url: api_url,
                data: $.param($scope.model),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            })
            .then(function (result) {
                var data = result.data;
                if (data.code == "success") {
                    layer.closeAll();
                    layer.msg("更新成功！");
                }
                else {
                    layer.closeAll();
                    layer.msg(data.message);
                }
            }, function (data) {
                layer.msg("系统错误!");
            });
        }
        else {
            layer.msg("一度好友和多度好友必须为整数！");
            return;
        }

    };
}]);